<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-08-13 14:08
 *
 * Version: 2.0
 */

namespace App\Modules\System\Repositories;


use App\Models\RoleAuthRule;
use App\Modules\System\Criterias\getRoleAuthRuleListCriteria;
use Flower\Core\Repository\Eloquent\BaseRepository;
use App\Lib\Utilities;
class RoleAuthRuleRepository extends BaseRepository
{
	public function model()
	{
		return RoleAuthRule::class;
	}

	/**
	 * 查询角色的权限ids列表
	 * @param array $roleId
	 * @return array
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 */
	public function getRoleAuth($roleId=null){
		$result = $this->pushCriteria(new getRoleAuthRuleListCriteria($roleId))->get(['role_id','auth_rule_id'])->toArray();
		$result = Utilities::arrayColumnGroup($result,null,'role_id');
		$result = array_map(function ($v){
			return array_column($v,'auth_rule_id');
		},$result);
		$list = [];
		array_walk_recursive($result, function($value) use (&$list) {
			array_push($list, $value);
		});
		$list = array_values(array_sort(array_unique($list)));
		return $list;
	}
}